﻿/*====================================================================================
* Copyright (c) 2015-2026成都长益西联软件有限公司,All Rights Reserved.
*=====================================================================================
* 文件名称：Random
* 功能描述：Random 
* 创 建 者：HFL
* 创建时间：2016-9-21 21:27:33
* 修 改 者：HFL
* 修改时间：2016-9-21 21:27:33
*===================================================================================*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;


namespace WPay.Infrastructure.Unity
{
    /// <summary>
    /// Random
    /// 提供功能【1：】
    /// </summary>
    public class RandomTool
    {
        /// <summary>
        /// 获取随机密码/验证码
        /// </summary>
        /// <param name="pwdLength">所需长度，默认4位</param>
        /// <returns>返回生成的密码/验证码</returns>
        public static string GetRandomCode(int pwdLength = 4)
        {
            string randomChars = "0123456789";
            string password = string.Empty;
            int randomNum;
            Random random = new Random();
            if (pwdLength < 1)
                pwdLength = 1;
            for (int i = 0; i < pwdLength; i++)
            {
                randomNum = random.Next(randomChars.Length);
                password += randomChars[randomNum];
            }
            return password;
        }
    }
}